﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户资料编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/lobsteruiframe/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/lobsteruiframe/layuiadmin/style/admin.css" rel="stylesheet" />
    <script src="/lobsteruiframe/layuiadmin/layui/layui.js"></script>
    <script src="/jslib/jquery-3.4.1.min.js"></script>
    <script src="/jslib/lobster.js"></script>

    <style>
        html, body {
            height: 100%;
        }
    </style>
</head>
<body>
    <div class="layui-card layui-form" style="height: 100%;padding-top:5px;" lay-filter="layuiadmin-form-myinfo">
        <div class="layui-form-item">
            <label class="layui-form-label"><i style="color:red;">*&ensp; </i>用户帐号</label>
            <div class="layui-input-inline">
                <input type="text" name="UserCode" lay-verify="required" autocomplete="off" class="layui-input" disabled>
            </div>
            <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-inline">
                <input type="text" id="Telephone" name="Telephone" lay-verify="chkphone" autocomplete="off" class="layui-input" disabled>
            </div>
            <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><i style="color:red;">*&ensp; </i>用户名称</label>
            <div class="layui-input-inline">
                <input type="text" name="Name" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-inline">
                <select id="sex" name="Sex">
                    <option value="1">男</option>
                    <option value="2">女</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">通信邮箱</label>
            <div class="layui-input-inline">
                <input type="text" id="email" name="Email" lay-verify="checkemail" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-inline">
                <input type="text" id="Address" name="Address" style="width:430px;" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <textarea class="layui-textarea" name="Memo" style="width:430px;" placeholder="请输入内容"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left:110px">
                <button class="layui-btn" lay-submit lay-filter="setmyinfo">确认修改</button>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="text" name="UserID" id="userID" value="0">
        </div>
    </div>
</body>
</html>

<script type="text/javascript">
    lobsterlayui.main(['index', 'layer', 'form', 'element'], {
        data: {
            $layui: null,
        },
        pageload: function () {
           
            this.initevent();
            this.GetUserInfo();
        },
        //初始化事件
        initevent: function () {
            var self = this;
            var layer = this.data.$layui.layer;
            var form = this.data.$layui.form;
            var element = this.data.$layui.element;

            //自定义验证规则
            form.verify({
                checkemail: function (value) {
                    var len = value.length, re;
                    if (len > 0) {
                        re = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
                        if (!re.test(value)) {
                            return '邮箱格式不对';
                        }
                    }
                }
            });

            //设置我的资料
            form.on('submit(setmyinfo)', function (data) {

                self.UpdateUserinfo(data);
            });
        },
        GetUserInfo: function () {
            var self = this;
            var layer = this.data.$layui.layer;
            var form = this.data.$layui.form;

            lobsterlayui.GET("/admin/v1/usersetup/GetUserInfo").then(data => {
                var myinfo = data["user"];
                form.val('layuiadmin-form-myinfo', myinfo);
            });

        },
        UpdateUserinfo: function (data) {
            var self = this;
            var layer = this.data.$layui.layer;
            var form = this.data.$layui.form;

            var field = data.field; //获取提交的字段
            var load = layer.msg('正在处理，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });

            lobsterlayui.POST("/admin/v1/usersetup/UpdateUserinfo", field).then(data => {
                layer.close(load);
                layer.msg("保存成功", { time: 1 * 1000 }, function () {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);//关闭弹层
                })
            }).catch(res => {
                layer.close(load);
                layer.msg(res.msg);
            });

            return false;
        }
    });


</script>